
public class e030 {
    public static void main(String[] args) {
        long sTime = System.currentTimeMillis();
        int sum = 0;
        for (int i = 2; i < 300000; i++) {
            if (canFifth(i)) {
                sum += i;
            }
        }
        System.out.println(sum);
        long fTime = System.currentTimeMillis();
        System.out.println("Time: " + (fTime - sTime) + "ms");
    }

    static boolean canFifth(int i) {
        String l = String.valueOf(i);
        int sum = 0;
        for(int j = 0; j < l.length(); j++) {
            int n = Integer.parseInt(String.valueOf(l.charAt(j)));
            sum += (n * n * n * n * n);
        }
        return (sum == i);
    }
}